public class jCalculate {
    public static void main(String[] args) {
        //计算1/1-1/2+1/3-…………-1/100的值
        double sum=0;
        int flg=1;
        for (int i = 0; i <=100; i++) {
            sum=sum+1.0/i*flg;//必须乘以1.0，转为double型
            flg=-flg;
        }
        System.out.println(sum);
    }
}
